//
//  OrderTopTableViewCell.m
//  rrqs
//
//  Created by 徐浩 on 2019/5/6.
//

#import "OrderTopTableViewCell.h"

@interface OrderTopTableViewCell()
//建议时间
@property (strong, nonatomic) UILabel *jianyishijianLabel;
//剩余时间
@property (strong, nonatomic) UILabel *shengyuShijianLabel;
//状态
@property (strong, nonatomic) UILabel *statusLabel;
//商店名称
@property (strong, nonatomic) UILabel *shopNameLabel;
//商店地址
@property (strong, nonatomic) UILabel *shopDizhiLabel;
//客户地址
@property (strong, nonatomic) UILabel *gukeDizhiLabel;
//派单时间
@property (strong, nonatomic) UILabel *paidanLabel;
//接单时间
@property (strong, nonatomic) UILabel *jiedanLabel;
@end

@implementation OrderTopTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        self.contentView.backgroundColor = [UIColor whiteColor];
        
        self.jianyishijianLabel = [[UILabel alloc]init];
        [self.contentView addSubview:self.jianyishijianLabel];
        [self.jianyishijianLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView.mas_left).offset(kSizeRatio(40));
            make.top.equalTo(self.contentView.mas_top).offset(13);
        }];
        self.jianyishijianLabel.text = @"建议12:00前送达";
        self.jianyishijianLabel.textColor = [UIColor blackColor];
        self.jianyishijianLabel.textAlignment = 0;
        self.jianyishijianLabel.font = kFontNameSize(14);
        
        UIImageView *timeImageView = [[UIImageView alloc]init];
        [self.contentView addSubview:timeImageView];
        [timeImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView.mas_left).offset(kSizeRatio(40));
            make.top.equalTo(self.jianyishijianLabel.mas_bottom).offset(10);
            make.size.mas_equalTo(CGSizeMake(kSizeRatio(24), kSizeRatio(24)));
        }];
        timeImageView.image = [UIImage imageNamed:@"order_time"];
        
        self.shengyuShijianLabel = [[UILabel alloc]init];
        [self.contentView addSubview:self.shengyuShijianLabel];
        [self.shengyuShijianLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(timeImageView.mas_right).offset(kSizeRatio(10));
//            make.top.equalTo(self.jianyishijianLabel.mas_bottom).offset(10);
            make.centerY.equalTo(timeImageView.mas_centerY);
        }];
        self.shengyuShijianLabel.text = @"剩余时间40分钟";
        self.shengyuShijianLabel.textColor = COLORRGB(0x999999);
        self.shengyuShijianLabel.textAlignment = 0;
        self.shengyuShijianLabel.font = kFontNameSize(12);
        
        self.statusLabel = [[UILabel alloc]init];
        [self.contentView addSubview:self.statusLabel];
        [self.statusLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.contentView.mas_right).offset(kSizeRatio(-40));
            make.top.equalTo(self.contentView.mas_top).offset(30);
        }];
        self.statusLabel.text = @"已确认";
        self.statusLabel.textColor = [UIColor blackColor];
        self.statusLabel.textAlignment = 0;
        self.statusLabel.font = kFontNameSize(14);
        
        UILabel *hengLabel = [[UILabel alloc]init];
        [self.contentView addSubview:hengLabel];
        [hengLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView.mas_left).offset(kSizeRatio(24));
            make.right.equalTo(self.contentView.mas_right).offset(kSizeRatio(-24));
            make.top.equalTo(self.shengyuShijianLabel.mas_bottom).offset(10);
            make.height.mas_equalTo(1);
        }];
        hengLabel.backgroundColor = COLORRGB(0x999999);
        
        UILabel *shopYuanLabel = [[UILabel alloc]init];
        [self.contentView addSubview:shopYuanLabel];
        [shopYuanLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView.mas_left).offset(kSizeRatio(40));
            make.top.equalTo(hengLabel.mas_bottom).offset(23);
            make.size.mas_equalTo(CGSizeMake(kSizeRatio(20), kSizeRatio(20)));
        }];
        shopYuanLabel.backgroundColor = COLORRGB(0xfdcc00);
        shopYuanLabel.layer.cornerRadius = kSizeRatio(20) / 2;
        shopYuanLabel.layer.masksToBounds = YES;

        
        
        self.shopNameLabel = [[UILabel alloc]init];
        [self.contentView addSubview:self.shopNameLabel];
        [self.shopNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(hengLabel.mas_bottom).offset(18);
            make.left.equalTo(shopYuanLabel.mas_right).offset(kSizeRatio(32));
        }];
        self.shopNameLabel.text = @"点吧超市";
        self.shopNameLabel.textColor = [UIColor blackColor];
        self.shopNameLabel.textAlignment = 0;
        self.shopNameLabel.font = kFontNameSize(14);

        UILabel *mapBtn = [[UILabel alloc]init];
        [self.contentView addSubview:mapBtn];
        [mapBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.contentView.mas_right).offset(kSizeRatio(-46));
            make.centerY.equalTo(self.shopNameLabel.mas_centerY);
        }];
        mapBtn.text = @"查看路线";
        mapBtn.textColor = COLORRGB(0xfdcc00);
        mapBtn.textAlignment = 0;
        mapBtn.font = kFontNameSize(14);
        [mapBtn setUserInteractionEnabled:YES];
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAciton)];
        [mapBtn addGestureRecognizer:tap];
        
        self.shopDizhiLabel = [[UILabel alloc]init];
        [self.contentView addSubview:self.shopDizhiLabel];
        [self.shopDizhiLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.shopNameLabel.mas_bottom).offset(4);
            make.left.equalTo(shopYuanLabel.mas_right).offset(kSizeRatio(32));
        }];
        self.shopDizhiLabel.text = @"浑南新区XXXX大厦";
        self.shopDizhiLabel.textColor = COLORRGB(0x999999);
        self.shopDizhiLabel.textAlignment = 0;
        self.shopDizhiLabel.font = kFontNameSize(11);

        UILabel *gukeYuanLabel = [[UILabel alloc]init];
        [self.contentView addSubview:gukeYuanLabel];
        [gukeYuanLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView.mas_left).offset(kSizeRatio(40));
            make.top.equalTo(self.shopDizhiLabel.mas_bottom).offset(16);
            make.size.mas_equalTo(CGSizeMake(kSizeRatio(20), kSizeRatio(20)));
        }];
        gukeYuanLabel.backgroundColor = COLORRGB(0x04d200);
        gukeYuanLabel.layer.cornerRadius = kSizeRatio(20) / 2;
        gukeYuanLabel.layer.masksToBounds = YES;

        self.gukeDizhiLabel = [[UILabel alloc]init];
        [self.contentView addSubview:self.gukeDizhiLabel];
        [self.gukeDizhiLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.shopDizhiLabel.mas_bottom).offset(14);
            make.left.equalTo(shopYuanLabel.mas_right).offset(kSizeRatio(32));
            make.right.equalTo(self.contentView.mas_right).offset(kSizeRatio(260));
        }];
        self.gukeDizhiLabel.text = @"浑南新区XXXXXXXXXXXXXXXXX大厦  |  2.3km";
        self.gukeDizhiLabel.textColor = [UIColor blackColor];
        self.gukeDizhiLabel.textAlignment = 0;
        self.gukeDizhiLabel.font = kFontNameSize(14);
        NSMutableAttributedString *AttributedStr = [[NSMutableAttributedString alloc]initWithString:@"浑南新区XXXXXXXXXXXXXXXXX大厦  |  2.3km"];
        [AttributedStr addAttribute:NSForegroundColorAttributeName value:COLORRGB(0x999999) range:NSMakeRange(AttributedStr.length - 9, 9)];
        self.gukeDizhiLabel.attributedText = AttributedStr;
        self.gukeDizhiLabel.numberOfLines = 2;

        UILabel *paidan = [[UILabel alloc]init];
        [self.contentView addSubview:paidan];
        [paidan mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView.mas_left).offset(kSizeRatio(46));
            make.top.equalTo(self.gukeDizhiLabel.mas_bottom).offset(12);
        }];
        paidan.text = @"派单时间";
        paidan.textColor = [UIColor blackColor];
        paidan.textAlignment = 0;
        paidan.font = kFontNameSize(13);

        self.paidanLabel = [[UILabel alloc]init];
        [self.contentView addSubview:self.paidanLabel];
        [self.paidanLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.contentView.mas_right).offset(kSizeRatio(-40));
            make.top.equalTo(self.gukeDizhiLabel.mas_bottom).offset(12);
        }];
        self.paidanLabel.text = @"2019-05-06 15:00";
        self.paidanLabel.textColor = [UIColor blackColor];
        self.paidanLabel.textAlignment = 2;
        self.paidanLabel.font = kFontNameSize(13);

        UILabel *jiedan = [[UILabel alloc]init];
        [self.contentView addSubview:jiedan];
        [jiedan mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView.mas_left).offset(kSizeRatio(46));
            make.top.equalTo(self.paidanLabel.mas_bottom).offset(10);
        }];
        jiedan.text = @"接单时间";
        jiedan.textColor = [UIColor blackColor];
        jiedan.textAlignment = 0;
        jiedan.font = kFontNameSize(13);

        self.jiedanLabel = [[UILabel alloc]init];
        [self.contentView addSubview:self.jiedanLabel];
        [self.jiedanLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.contentView.mas_right).offset(kSizeRatio(-40));
            make.top.equalTo(self.paidanLabel.mas_bottom).offset(10);
        }];
        self.jiedanLabel.text = @"2019-05-06 15:00";
        self.jiedanLabel.textColor = [UIColor blackColor];
        self.jiedanLabel.textAlignment = 2;
        self.jiedanLabel.font = kFontNameSize(13);
        
        UILabel *hengLabel1 = [[UILabel alloc]init];
        [self.contentView addSubview:hengLabel1];
        [hengLabel1 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.bottom.equalTo(self.contentView);
            make.top.equalTo(self.jiedanLabel.mas_bottom).offset(10);
            make.height.mas_equalTo(10);
        }];
        hengLabel1.backgroundColor = COLORRGB(0xededed);
    }
    return self;
}

-(void)tapAciton
{
    if (self.OrderTopTableViewCellDelegate && [self.OrderTopTableViewCellDelegate respondsToSelector:@selector(clickMap)]) {
        [self.OrderTopTableViewCellDelegate clickMap];
    }
}

-(void) reloadUIWithDic:(NSDictionary *)dic
{
    self.jianyishijianLabel.text =  [Config isBlankString:[NSString stringWithFormat:@"%@",dic[@"reas_time"]]] ? @"建议前送达" : [NSString stringWithFormat:@"建议%@前送达",dic[@"reas_time"]];
    self.shengyuShijianLabel.text =  [Config isBlankString:[NSString stringWithFormat:@"%@",dic[@"shengyu"]]] ? @"剩余分钟" : [NSString stringWithFormat:@"剩余%@分钟",dic[@"shengyu"]];
    self.statusLabel.text = [Config isBlankString:[NSString stringWithFormat:@"%@",dic[@"order_status"]]] ? @"" : [NSString stringWithFormat:@"%@",dic[@"order_status"]];
    self.shopNameLabel.text = [Config isBlankString:[NSString stringWithFormat:@"%@",dic[@"amin_name"]]] ? @"" : [NSString stringWithFormat:@"%@",dic[@"amin_name"]];
    self.shopDizhiLabel.text = [Config isBlankString:[NSString stringWithFormat:@"%@",dic[@"send_address"]]] ? @"" : [NSString stringWithFormat:@"%@",dic[@"send_address"]];
    self.gukeDizhiLabel.text = [Config isBlankString:[NSString stringWithFormat:@"%@",dic[@"get_address"]]] ? @"" : [NSString stringWithFormat:@"%@",dic[@"get_address"]];
    self.paidanLabel.text = [Config isBlankString:[NSString stringWithFormat:@"%@",dic[@"paidan_time"]]] ? @"" : [NSString stringWithFormat:@"%@",dic[@"paidan_time"]];
    self.jiedanLabel.text = [Config isBlankString:[NSString stringWithFormat:@"%@",dic[@"jiedan_time"]]] ? @"" : [NSString stringWithFormat:@"%@",dic[@"jiedan_time"]];
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
